package lab2;

import java.util.*;
import java.util.stream.Collectors;

public class StudentTest {

    /**
     * [ low, up)
     *
     * @param random
     * @param low
     * @param up
     * @return
     */
    public static double random(Random random, double low, double up) {
        return (up - low) * random.nextDouble() + low;
    }

    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();

        Random random = new Random();
        Random random2 = new Random();

        for (int i = 0; i < 100; i++) {
//            Random random = new Random();
            double random1 = random(random, 0.0, 5.0);
            int randomNum = (int) random(random, 0, 9000000);
//            double random1 = random(random, 0.0, 5.0);
//            double randomName = random(random, 0, 1000);
            int i1 = random.nextInt();
            String str1 = i1 + "";
            String chineseName =RandomName. randomName(true,3);

//            list.add(new Student(i+"",i1,i%2==0?"男":"女",random1*1.0));
//            list.add(new Student(i + "", randomNum, i % 2 == 0 ? "男" : "女", random1 * 1.0));
            list.add(new Student(chineseName, randomNum, i % 2 == 0 ? "男" : "女", random1 * 1.0));
        }
        System.out.println("list");
        System.out.println(list);
        List<Student> odokos = list.stream().filter(stu -> stu.getSex().equals("男")).collect(Collectors.toList());
        System.out.println("odokos");
        System.out.println(odokos);
//        , Comparator.reverseOrder()
//,Comparator.reverseOrder()
        Collection<Student> odokosFirst5 = list.stream().filter(stu -> stu.getSex().equals("男")).
                sorted(Comparator.comparingDouble(Student::getScore).reversed())
                .limit(5).collect(Collectors.toList());
        System.out.println("odokosFirst5");
        System.out.println(odokosFirst5);
    }
}
